// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  const userInfo = event.userInfo;

  return await cloud.database().collection('user_info').add({
    data: {
      account:       userInfo.account,
      avater:        userInfo.avater,
      birth:         userInfo.birth,
      lastLoginTime: userInfo.lastLoginTime,
      nickName:      userInfo.nickName,
      password:      userInfo.password,
      phone:         userInfo.phone,
      realName:      userInfo.realName,
      sex:           userInfo.sex,
      type:          userInfo.type,
      myAsk:         userInfo.myAsk,
      myDoctor:      userInfo.myDoctor,
      myCar:         userInfo.myCar,
      myOrder:       userInfo.myOrder
    },
    success: res => {
      console.log("add user success", res);
      return true;
    },
    fail: res => {
      console.log("add user fail", res);
      return false;
    }
  })
}